package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.model.PopupPrompt;
import net.zoneland.knowledge.model.PopupPromptLog;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 新功能提醒数据层.
 * @author wangzhiwei
 * @date 2023/5/24
 */
@Mapper
public interface PopupPromptMapper {

    /**
     * 根据用户id查新功能id
     * @param userId 用户id
     * @return
     */
    @Select({"SELECT NEW_FUNCTION_ID FROM AITK_POPUP_PROMPT_LOG appl WHERE USER_ID = #{userId, jdbcType=VARCHAR}"})
    @Results({
            @Result(column="NEW_FUNCTION_ID", property="newFunctionId", jdbcType=JdbcType.VARCHAR),
            @Result(column="USER_ID", property="userId", jdbcType=JdbcType.VARCHAR)
    })
    List<PopupPromptLog> findPopupPromptLogByUserId(final @Param("userId") String userId);


    /**
     * 添加数据到新功能日志表
     * @param uuid 主键id
     * @param userId 用户ID
     * @param userName 用户名称
     * @param newFunctionId 新功能id
     */
    @Insert({"INSERT INTO AITK_POPUP_PROMPT_LOG (ID, USER_ID, USER_NAME, NEW_FUNCTION_ID) " +
            "VALUES (#{id, jdbcType=VARCHAR}, #{userId, jdbcType=VARCHAR}, #{userName, jdbcType=VARCHAR}, #{newFunctionId, jdbcType=VARCHAR})"})
    void addPopupPromptLog(final @Param("id")String uuid,
                                   final @Param("userId") String userId,
                                   final @Param("userName") String userName,
                                   final @Param("newFunctionId") String newFunctionId);

    /**
     * 查看功能提醒表id
     * @return 功能表id集合.
     */
    @Select({"SELECT ID FROM AITK_POPUP_PROMPT WHERE SYSDATE < FAIL_TIME ORDER BY ENTRY_TIME DESC"})
    List<PopupPrompt> findPopupPromptId();

    /**
     * 根据id获取内容.
     * @param id id集合
     * @return 离当前时间最近的一条内容.
     */
    @Select({"SELECT CONTENT, ID FROM AITK_POPUP_PROMPT WHERE ID = #{id, jdbcType=VARCHAR}"})
    PopupPrompt findContentById(final @Param("id") String id);


}
